<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>后台管理</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<link rel="stylesheet" th:href="@{/css/font.css}">
<link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/commons.css}"/>
<link rel="stylesheet" th:href="@{/css/font.css}">
<link rel="stylesheet" th:href="@{/css/weadmin.css}">
<script type="text/javascript">
var ctx = '[[${#httpServletRequest.getContextPath()}]]';  
</script>
<script type="text/javascript" th:src="@{/jquery/jquery.js}"></script>
<script th:src="@{/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/js/commons.js}"></script>
</head>
<body>
	<!-- 顶部开始 -->
<div class="container">
	<div class="logo">
		<a href="#">基础管理系统</a>
	</div>
	<div class="left_open">
		<i title="展开左侧栏" class="layui-icon layui-icon-prev"></i>
	</div>
	<ul class="layui-nav right">
		<li class="layui-nav-item">
			<a href="javascript:;" id="username"></a>
			<!-- <a href="/">前台首页</a> -->
		</li>
		<li class="layui-nav-item">
			<!-- <a href="/">前台首页</a> -->
			<a class="loginout" th:href="@{/logout}">退出</a>
		</li>
	</ul>
</div>
<!-- 顶部结束 -->
<!-- 中部开始 -->
<!-- 左侧菜单开始 -->
<div class="left-nav">
	<div id="side-nav">
		<ul id="nav">
		</ul>
	</div>
</div>
<!-- 左侧菜单结束 -->
<!-- 右侧主体开始 -->
<div class="page-content">
	<div class="layui-tab tab" lay-filter="wenav_tab" id="WeTabTip" lay-allowclose="true">
		<ul class="layui-tab-title" id="tabName">
			<li>首页</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<iframe th:src='@{/index}' frameborder="0" scrolling="yes" class="weIframe"></iframe>
			</div>
		</div>
	</div>
</div>
<div class="page-content-bg"></div>
<!-- 右侧主体结束 -->
<!-- 中部结束 -->
<!-- 底部开始 -->
<div class="footer">
	<div class="copyright" style="text-align:center">Copyright ©2018 TREK All Rights Reserved</div>
</div>
<!-- 底部结束 -->
<script type="text/javascript">
layui.use('element', function(){
    var element = layui.element;
    var $ = layui.jquery;
	
    getUserInfo();
    createSysMenu();
    // 获取个人信息
    function getUserInfo(){
    	commons.ajax({
    		url : ctx + '/userInfo',
    		success : function(res){
    			$('#username').html(res.data.sysUser.name);
    		},
    		fail : function(res){
    			layer.msg(res.msg);
    		}
    	});
    }
    
    
    // 生成菜单
    function createSysMenu(){
    	$.ajax({
            url:ctx+"/sys/acl/sysMenu",
            type:"get",
            dataType:"json",
            data:{},
            success:function(res){
            	var data = res.data;
                var liStr= "";
                // 遍历生成主菜单
                for( var i = 0; i <data.length; i++){
                    // 判断是否存在子菜单
                    if(data[i].children!=null&&data[i].children.length>0){
                        liStr+="<li><a _href='javascript:;'><i class='iconfont'>&#xe6b8;</i><cite>"+data[i].name+"</cite><i class='iconfont nav_right'>&#xe697;</i></a>";
                        // 遍历获取子菜单
                        for( var k = 0; k <data[i].children.length; k++){
                            liStr+=getChildMenu(data[i].children[k],0);
                        } 
                        liStr+="</li>";
                    }else{
                        liStr+="<li><a _href='"+ctx+data[i].url+"'><i class='iconfont'>&#xe6b8;</i><cite>"+data[i].name+"</cite></a></li>";
                    }
                };
                
                $("#nav").html(liStr);
                element.init();
                
                layui.config({
              	  base: './js/' 
              	}).use('admin');
                
            }
        });
    }
    

});

 // 递归生成子菜单
 function getChildMenu(subMenu,num) {
     num++;
     var subStr = "<ul class='sub-menu'>";
     if(subMenu.children!=null&&subMenu.children.length>0){
         subStr+="<li><a _href='javascript:;'><i class='iconfont'>&#xe6b8;</i><cite>"+subMenu.name+"</cite><i class='iconfont nav_right'>&#xe697;</i></a></li>";
         for( var j = 0; j <subMenu.children.length; j++){
             subStr+=getChildMenu(subMenu.children[j],num);
         }
         subStr +="</li>";
     }else{
         subStr+="<li><a _href='"+ctx+subMenu.url+"'><i class='iconfont'>&#xe6b8;</i><cite>"+subMenu.name+"</cite></li>";
     }
     subStr+="</ul>";
     return subStr;
 }
</script>
</body>
	<!--Tab菜单右键弹出菜单-->
	<ul class="rightMenu" id="rightMenu">
        <li data-type="fresh">刷新</li>
        <li data-type="current">关闭当前</li>
        <li data-type="other">关闭其它</li>
        <li data-type="all">关闭所有</li>
    </ul>
</html>